package com.seek.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seek.commonutils.ResponseResult;
import com.seek.eduservice.entity.EduCourse;
import com.seek.eduservice.entity.EduTeacher;
import com.seek.eduservice.service.EduCourseService;
import com.seek.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author: wml
 * @since: 2022/2/22 23:06
 */
@RestController
@RequestMapping("/eduservice/teacher")
public class TeacherController {

    @Autowired
    private EduTeacherService eduTeacherService;

    @Autowired
    private EduCourseService eduCourseService;

    // 分页查询讲师
    @GetMapping("page/{current}/{size}")
    public ResponseResult page(@PathVariable long current, @PathVariable long size) {
        Page<EduTeacher> page = new Page<>(current, size);
        Map<String, Object> map = eduTeacherService.selectPage(page);
        return ResponseResult.ok().data(map);
    }

    // 查询讲师详情
    @GetMapping("getTeacherInfo/{teacherId}")
    public ResponseResult getTeacherInfo(@PathVariable String teacherId) {
        // 根据讲师 id 查询讲师基本信息
        EduTeacher eduTeacher = eduTeacherService.getById(teacherId);

        // 根据讲师 id 查询所有课程
        QueryWrapper<EduCourse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teacher_id", teacherId);
        List<EduCourse> eduCourseList = eduCourseService.list(queryWrapper);
        return ResponseResult.ok().data("teacher", eduTeacher).data("courseList", eduCourseList);
    }
}
